﻿using System;
using System.Collections.Generic;
using System.Reflection;
using System.Text;



namespace Open.Data.Persistence
{
    public class Comparison: Condition
    {
        public Comparison(Expression expression, Expression compareTo): base()
        {
            Expression = expression;
            CompareTo = compareTo;
            Operator = ComparisonOperator.Equal;
        }

        public Comparison(Expression expression, Expression compareTo, ComparisonOperator op): base()
        {
            Expression = expression;
            CompareTo = compareTo;
            Operator = op;
        }

        public Comparison(Expression expression, string compareTo): base()
        {
            Expression = expression;
            CompareTo = new StringParameter(compareTo);
            Operator = ComparisonOperator.Equal;
        }

        public Comparison(Expression expression, string compareTo, ComparisonOperator op): base()
        {
            Expression = expression;
            CompareTo = new StringParameter(compareTo);
            Operator = op;
        }

        public Comparison(Expression expression, long compareTo)
            : base()
        {
            Expression = expression;
            CompareTo = new LongParameter(compareTo);
            Operator = ComparisonOperator.Equal;
        }

        public Comparison(Expression expression, long compareTo, ComparisonOperator op): base()
        {
            Expression = expression;
            CompareTo = new LongParameter(compareTo);
            Operator = op;
        }

        public Comparison(Expression expression, int compareTo): base()
        {
            Expression = expression;
            CompareTo = new IntegerParameter(compareTo);
            Operator = ComparisonOperator.Equal;
        }

        public Comparison(Expression expression, int compareTo, ComparisonOperator op): base()
        {
            Expression = expression;
            CompareTo = new IntegerParameter(compareTo);
            Operator = op;
        }

        public Comparison(Expression expression, DateTime compareTo): base()
        {
            Expression = expression;
            CompareTo = new DateTimeParameter(compareTo);
            Operator = ComparisonOperator.Equal;
        }

        public Comparison(Expression expression, DateTime compareTo, ComparisonOperator op): base()
        {
            Expression = expression;
            CompareTo = new DateTimeParameter(compareTo);
            Operator = op;
        }

        public Comparison(Expression expression, bool compareTo): base()
        {
            Expression = expression;
            CompareTo = new BooleanParameter(compareTo);
            Operator = ComparisonOperator.Equal;
        }

        public Comparison(Expression expression, bool compareTo, ComparisonOperator op): base()
        {
            Expression = expression;
            CompareTo = new BooleanParameter(compareTo);
            Operator = op;
        }

        public Comparison(Expression expression, byte compareTo): base()
        {
            Expression = expression;
            CompareTo = new ByteParameter(compareTo);
            Operator = ComparisonOperator.Equal;
        }

        public Comparison(Expression expression, byte compareTo, ComparisonOperator op): base()
        {
            Expression = expression;
            CompareTo = new ByteParameter(compareTo);
            Operator = op;
        }

        public Comparison(Expression expression, short compareTo): base()
        {
            Expression = expression;
            CompareTo = new ShortParameter(compareTo);
            Operator = ComparisonOperator.Equal;
        }

        public Comparison(Expression expression, short compareTo, ComparisonOperator op): base()
        {
            Expression = expression;
            CompareTo = new ShortParameter(compareTo);
            Operator = op;
        }

        public Expression Expression { get; set; }
        public Expression CompareTo { get; set; }
        public ComparisonOperator Operator { get; set; }

        public override IEnumerable<Expression> GetExpressions()
        {
            yield return Expression;
            yield return CompareTo;
        }

        public override void AppendHashCode(StringBuilder builder)
        {
            Expression.AppendHashCode(builder);
            builder.Append(Operator.ToString());
            CompareTo.AppendHashCode(builder);
        }
    }

}
